﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using Maticsoft.Common;
using LTP.Accounts.Bus;
namespace XDSoft.Web.TB_Clients
{
    public partial class Add : Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            XDSoft.BLL.TB_Options bll = new XDSoft.BLL.TB_Options();
            this.ddlClientLevel.AppendDataBoundItems = true;
            this.ddlClientLevel.Items.Add(new ListItem("", ""));
            this.ddlClientLevel.DataSource = bll.GetModelList("parent='" + EnumCommon.OptionsType.ClientLevel.ToString() + "'");
            this.ddlClientLevel.DataTextField = "name";
            this.ddlClientLevel.DataValueField = "id";
            this.ddlClientLevel.DataBind();
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {

            string strErr = "";
            if (this.txtclientName.Text.Trim().Length == 0)
            {
                strErr += "客户名称不能为空！\\n";
            }

            if (strErr != "")
            {
                MessageBox.Show(this, strErr);
                return;
            }
            string clientName = this.txtclientName.Text;
            string corpName = this.txtcorpName.Text;
            string address = this.txtaddress.Text;
            string tel = this.txttel.Text;
            string mobile1 = this.txtmobile1.Text;
            string mobile2 = this.txtmobile2.Text;
            string webUrl = this.txtwebUrl.Text;
            string email = this.txtemail.Text;
            string qq = this.txtqq.Text;
            string traceLog = this.txttraceLog.Text;
            string memo = this.txtmemo.Text;
            string clientLevel = this.ddlClientLevel.SelectedValue;

            XDSoft.Model.TB_Clients model = new XDSoft.Model.TB_Clients();
            model.clientName = clientName;
            model.corpName = corpName;
            model.address = address;
            model.tel = tel;
            model.mobile1 = mobile1;
            model.mobile2 = mobile2;
            model.webUrl = webUrl;
            model.email = email;
            model.qq = qq;
            model.traceLog = traceLog;
            model.memo = memo;
            model.clientLevel = clientLevel;

            XDSoft.BLL.TB_Clients bll = new XDSoft.BLL.TB_Clients();
            if (bll.Add(model) > 0)
                Maticsoft.Common.MessageBox.ShowAndRedirect(this, "保存成功！", "add.aspx");
            else
                Maticsoft.Common.MessageBox.Show(this, "保存失败！");

        }
    }
}
